package com.dynamicprogram;

import java.util.Arrays;
import java.util.HashMap;

public class Solution2140 {
    public long mostPoints(int[][] questions) {
        int m = questions.length;
        long[] dp = new long[m];
        dp[m - 1] = questions[m - 1][0];
        for (int i = m - 2; i >= 0; i--) {
            int j = i + questions[i][1] + 1;
            dp[i] = j < m ? questions[i][0] + dp[j] : questions[i][0];
            dp[i] = Math.max(dp[i], dp[i + 1]);
        }
        return dp[0];
    }
}
